package com.tmp.alarm.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class UUIDByDateUtils {

	private  final  static Logger LOGGER = LoggerFactory.getLogger(UUIDByDateUtils.class);

	public  static  void  main(String []args){

		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		try {
			Date date = sdf.parse("20180103191800");
			long st = date.getTime();

			long cur = System.currentTimeMillis();

			long s = (cur-st)/1000;
			LOGGER.info(s+"");
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}


	/**
	 * 获取自定义的时间格式的毫秒数
	 * @param format
	 * @return
     */
	public static long geSelfTimes(String format,String dates){

		long times = 0L;
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		try {
			Date date = sdf.parse(dates);
			times = date.getTime();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return times;
	}

	/**
	 * 保留小数点后两位小数
	 * @param numbers
	 * @return
     */
	public  static  String twoPointNumbers(String numbers){

		DecimalFormat df  =new DecimalFormat("#.00");
		String res = df.format(Double.parseDouble(numbers.trim()));
		return  res;
	}

	/**
	 * @return
     */
	public static String getCurrentTimes(String format){
		
        Date current = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        String currentDate = sdf.format(current);
        return currentDate;
	}
	
	/**
	 * 得到当前时间对应的目录级别串
	 * 2016/12/02/13/21
	 * @return
	 */
	public static String getFileCatalog(){
		
		Date current = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentDate = sdf.format(current);
        
        String date = currentDate.split(" ")[0];
        String time = currentDate.split(" ")[1];
        
        String y = date.split("-")[0];
        String m = date.split("-")[1];
        String d = date.split("-")[2];
        
        String h = time.split(":")[0];
        String mm = time.split(":")[1];
        
        String catalog = y+"/"+m+"/"+d+"/"+h+"/"+mm;
		
		return catalog;
	}

	/**
	 * 
	 * <p>Description:获取当前的时间24h制 </p>
	 * <p>date : 2016年5月10日 下午8:13:49 </p>
	 * @author lhj
	 */
	public String getCurrentTime(){
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String current = sdf.format(date);
		return current;
	}


	/**
	 * 
	 * <p>Description:获取转换后的自定义时间格式 </p>
	 * <p>date : 2016年5月14日 上午8:40:55 </p>
	 */
	public static String getFormatDate(Date date){
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(date);
	} 
}
